//
//  RootViewController.m
//  轮播图
//
//  Created by dllo on 16/1/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "NHScrollView.h"
#import "NetWorkingTool.h"

@interface RootViewController ()<NHScrollViewDataSource>

@property(nonatomic, retain)NSMutableArray *imagesArr;
// 基于ScrollView的轮播图
@property(nonatomic, retain)NHScrollView *scrollView;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.    
    
    // 读取数据
    [self createData];
    
    // 创建视图
    [self createView];
    
}
#pragma mark 读取数据
- (void)createData{
    
    NSString *urlStr = @"http://mobile.ximalaya.com/m/super_explore_index2?channel=ios-b1&device=iPhone&includeActivity=true&picVersion=9&scale=2&version=3.1.43";
    [NetWorkingTool netWorkingWithStrURL:urlStr block:^(id result) {
        
        NSArray *arr = result[@"focusImages"][@"list"];
        self.imagesArr = [NSMutableArray array];
        for (NSDictionary *tempDic in arr) {
            [self.imagesArr addObject:tempDic[@"pic"]];
        }
        [self.scrollView reloadData];
    }];
    
    
    
}

#pragma mark 创建视图
- (void)createView{
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 创建轮播图
    self.scrollView = [[NHScrollView alloc] initWithFrame:CGRectMake(30, 50, 350, 200) NHScrollViewStyle:NHScrollViewStyleAutomaticInfiniteLoop];
    [self.view addSubview:self.scrollView];
    
    // 签协议,指定代理人
    self.scrollView.dataSource = self;
    
}
#pragma mark 实现NHSCrollView的协议方法
// 返回数据
- (NSArray<NSString *> *)bringImageDataNHScrollView:(NHScrollView *)scrollView{
    return self.imagesArr;
}
// 点击方法
- (void)scrollView:(NHScrollView *)scrollView didSeclectRowAtIndexPath:(NSInteger)indexPathRow{
    NSLog(@"点击了第%ld个图片",indexPathRow);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
